﻿using Mobileterminal.Common;
using Mobileterminal.Dtos;
using Newtonsoft.Json;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mobileterminal.Forms.Zyy
{
    public partial class Addshelf : UIEditForm
    {
        public static List<shelefs> appsTypes = new List<shelefs>();
        public Addshelf()
        {
            InitializeComponent();
            GetApps();
        }

        private void uiLabel1_Click(object sender, EventArgs e)
        {

        }

        private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
   

        private async void btnOK_Click(object sender, EventArgs e)
        {

          
            var pdata = new
            {
                ShelfId = 0,
                Superiorshelf = uiComboBox1.Text,
                Shelfcode = uiTextBox1.Text,
                Shelfname = uiTextBox2.Text,
                Shelflayers = uiTextBox3.Text,

                Shelfcells = uiTextBox4.Text,
                Shelfbarcode = uiTextBox5.Text,
           
            };
            string jsonParam = JsonConvert.SerializeObject(pdata);
            HttpContent httpContent = new StringContent(jsonParam, Encoding.UTF8, "application/json");
            var json = await HttpClientHelper.ClientAsync("post", "https://localhost:7286/api/Shelfdictionary/Handle", true, httpContent);
            shelefs result = JsonConvert.DeserializeObject<shelefs>(json);


           if (result != null)
            {
                MessageBox.Show("添加成功");
                this.DialogResult = DialogResult.OK;  // 先设置结果
                this.Close();

            }

        }

        private void Addshelf_Load(object sender, EventArgs e)
        {

        }

        private void uiLabel6_Click(object sender, EventArgs e)
        {

        }

        private void uiComboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (uiComboBox1.SelectedValue != null)
            {
             /*   int customerId = Convert.ToInt32(uiComboBox1.SelectedValue);
                Console.WriteLine($"Selected Customer ID: {customerId}");*/
            }
        }

        private async Task GetApps()
        {            //https://localhost:7224/api/Shelfdictionary/XiaSgelf
            var url = "https://localhost:7224/api/Shelfdictionary/XiaSgelf";


     
            var json = await HttpClientHelper.ClientAsync("GET", url);
           // var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<List<shelefs>>>(json);
            var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<List<shelefs>>>(json);
            if (result.Code == 200)
            {

                uiComboBox1.DataSource = result.Data;
                uiComboBox1.DisplayMember = "Superiorshelf";
                uiComboBox1.ValueMember = "ShelfId";
                appsTypes = result.Data;
            }
        }

        private void uiLabel7_Click(object sender, EventArgs e)
        {

        }
    }
}
